home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
FromTheMag
/
JW FLV MEDIA PLAYER 4.2
/
mediaplayer.exe
/
player.swf
/
scripts
/
com
/
jeroenwijering
/
models
/
ImageModel.as
< prev
next >
Wrap
Text File
|
2008-11-04
|
4KB
|
145 lines
package com.jeroenwijering.models
{
import com.jeroenwijering.events.ModelEvent;
import com.jeroenwijering.events.ModelStates;
import com.jeroenwijering.player.Model;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.utils.clearInterval;
import flash.utils.setInterval;
public class ImageModel implements ModelInterface
{
private var interval:Number;
private var loader:Loader;
private var position:Number;
private var model:Model;
public function ImageModel(param1:Model)
{
super();
model = param1;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderHandler);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
}
public function stop() : void
{
SoundMixer.stopAll();
clearInterval(interval);
if(loader.contentLoaderInfo.bytesLoaded != loader.contentLoaderInfo.bytesTotal)
{
loader.close();
}
else
{
loader.unload();
}
}
public function quality(param1:Boolean) : void
{
var stt:Boolean = param1;
try
{
Bitmap(loader.content).smoothing = stt;
}
catch(err:Error)
{
}
}
public function seek(param1:Number) : void
{
clearInterval(interval);
position = param1;
play();
}
public function volume(param1:Number) : void
{
}
private function progressHandler(param1:ProgressEvent) : void
{
var _loc2_:* = undefined;
_loc2_ = Math.round(param1.bytesLoaded / param1.bytesTotal * 100);
model.sendEvent(ModelEvent.BUFFER,{"percentage":_loc2_});
}
private function errorHandler(param1:ErrorEvent) : void
{
model.sendEvent(ModelEvent.ERROR,{"message":param1.text});
}
public function load() : void
{
clearInterval(interval);
position = model.playlist[model.config["item"]]["start"];
loader.load(new URLRequest(model.playlist[model.config["item"]]["file"]));
model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.BUFFERING});
model.sendEvent(ModelEvent.BUFFER,{"percentage":0});
}
private function timeInterval() : void
{
var _loc1_:* = undefined;
position = Math.round(position * 10 + 1) / 10;
_loc1_ = model.playlist[model.config["item"]]["duration"];
if(position >= _loc1_ && _loc1_ > 0)
{
clearInterval(interval);
SoundMixer.stopAll();
model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.COMPLETED});
}
else if(_loc1_ > 0)
{
model.sendEvent(ModelEvent.TIME,{
"position":position,
"duration":_loc1_
});
}
}
public function play() : void
{
interval = setInterval(timeInterval,100);
model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.PLAYING});
}
public function pause() : void
{
clearInterval(interval);
model.sendEvent(ModelEvent.STATE,{"newstate":ModelStates.PAUSED});
}
private function loaderHandler(param1:Event) : void
{
model.mediaHandler(loader);
quality(model.config["quality"]);
play();
model.sendEvent(ModelEvent.META,{
"height":param1.target.height,
"width":param1.target.width
});
model.sendEvent(ModelEvent.LOADED,{
"loaded":param1.target.bytesLoaded,
"total":param1.target.bytesTotal
});
}
}
}